package com.azusa.ktc_search.service;

import com.azusa.ktc_search.dao.ArticleSearchDao;
import com.azusa.ktc_search.entity.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import utils.IdWorker;

import java.util.List;
import java.util.Map;

/**
 * @Description 文章 服务层
 * @author Azusa
 * @date 2020-10-12 18:16:12
*/
@Service
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleSearchDao articleDao;

	@Autowired
	private IdWorker idWorker;

	/**
	* 增加
	* @param article
	*/
	public void add(Article article) {
		article.setId( idWorker.nextId()+"" );
		articleDao.save(article);
	}

	@Override
	public Page<Article> search(String keywords, int page, int size) {
		return  articleDao.findByTitleLikeOrContentLike(keywords,keywords, PageRequest.of(page-1,size));
	}
}
